import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

public class Thread29 {
    public static void main(String[] args) {
        BlockingQueue<Integer> n = new LinkedBlockingQueue<>();
        Thread producer=new Thread(()->{
            int count=0;
            while(true)
            {
                try {
                    n.put(count);
                    Thread.sleep(500);
                    count++;
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }

        });
        Thread  consumer=new Thread(()->{
            while(true)
            {
                try {
                    Integer cur=n.take();
                    System.out.println(cur);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

        });
        producer.start();
        consumer.start();


    }
}
